
import com.jme3.network.Client;
import com.jme3.network.Network;
import com.jme3.network.serializing.Serializer;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author David Zhang
 */
public class ClientMain {
    int myIndex = -1, playernum = 0;
    ArrayList<Player> players = new ArrayList<Player>();
    Client client;
    
    public ClientMain(){
        Serializer.registerClass(ChatMessage.class);
        try {
            client = Network.connectToServer("chat", 1, "91.227.124.244", 8080, 8080);
        } catch (IOException ex) {
            System.out.println("Unable to Connect");
            System.exit(0);
        }
        client.addMessageListener(new ChatHandler(), ChatMessage.class);
        client.start();
        Main.app.getInputManager().setCursorVisible(true);
    }
    
    public void send(String newtext){
        if(!newtext.equals("")){
            ChatMessage chat = new ChatMessage("chat", newtext);
            chat.setReliable(true);
            client.send(chat);
        }
    }
}